<?php

namespace app\admin\model\user;

use app\common\model\shopro\ShoproPerformanceModel;
use think\Model;


class Userquyu extends Model
{

    

    

    // 表名
    protected $name = 'user';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'area_text',
        'is_experience_store_text',
        'prevtime_text',
        'logintime_text',
        'jointime_text',
        'status_text',
        'is_frozen_text',
        'is_lock_text',
        'is_old_text',
        'is_manager_text',
        'is_withdraw_text',
        'is_firepower_text',
        'a_performance_text',
        'b_performance_text'
    ];
    

    
    public function getAreaList()
    {
        return ['A' => __('A'), 'B' => __('B')];
    }

    public function getIsExperienceStoreList()
    {
        return ['1' => __('Is_experience_store 1'), '0' => __('Is_experience_store 0')];
    }

    public function getStatusList()
    {
        return ['50' => __('Status 50')];
    }

    public function getIsFrozenList()
    {
        return ['0' => __('Is_frozen 0'), '1' => __('Is_frozen 1')];
    }

    public function getIsLockList()
    {
        return ['0' => __('Is_lock 0'), '1' => __('Is_lock 1')];
    }

    public function getIsOldList()
    {
        return ['1' => __('Is_old 1'), '0' => __('Is_old 0')];
    }

    public function getIsManagerList()
    {
        return ['1' => __('Is_manager 1'), '0' => __('Is_manager 0')];
    }

    public function getIsWithdrawList()
    {
        return ['1' => __('Is_withdraw 1'), '0' => __('Is_withdraw 0')];
    }

    public function getIsFirepowerList()
    {
        return ['1' => __('Is_firepower 1'), '0' => __('Is_firepower 0')];
    }


    public function getAreaTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['area']) ? $data['area'] : '');
        $list = $this->getAreaList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsExperienceStoreTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_experience_store']) ? $data['is_experience_store'] : '');
        $list = $this->getIsExperienceStoreList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPrevtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['prevtime']) ? $data['prevtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getLogintimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getJointimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['jointime']) ? $data['jointime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsFrozenTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_frozen']) ? $data['is_frozen'] : '');
        $list = $this->getIsFrozenList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsLockTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_lock']) ? $data['is_lock'] : '');
        $list = $this->getIsLockList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsOldTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_old']) ? $data['is_old'] : '');
        $list = $this->getIsOldList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsManagerTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_manager']) ? $data['is_manager'] : '');
        $list = $this->getIsManagerList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsWithdrawTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_withdraw']) ? $data['is_withdraw'] : '');
        $list = $this->getIsWithdrawList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsFirepowerTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_firepower']) ? $data['is_firepower'] : '');
        $list = $this->getIsFirepowerList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setPrevtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setLogintimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setJointimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getAperformanceTextAttr($value,$data)
    {
        if(isset($data['id'])){
            $model = new ShoproPerformanceModel();
            $value = $model->where(['user_id'=>$data['id']])->sum('a_money');
        }
        return $value;
    }

    public function getBperformanceTextAttr($value,$data)
    {
        if(isset($data['id'])){
            $model = new ShoproPerformanceModel();
            $value = $model->where(['user_id'=>$data['id']])->sum('b_money');
        }
        return $value;
    }

}
